package Threadprojects.pro2_knn.util;

import Threadprojects.pro2_knn.bean.Sample;

public class EuclideDistanceCalculate implements DistanceCalculator{
    @Override
    public double calculate(Sample sample1,Sample sample2){
        double ret=0.0;
        double[] data1 = sample1.getExample();
        double[] data2 = sample2.getExample();
        if (data1.length!=data2.length){
            throw new IllegalArgumentException("样本数据不一致");
        }
        for (int i = 0; i < data1.length; i++) {
            ret+=Math.pow(data1[i]-data2[i],2);

        }
        return Math.sqrt(ret);
    }
}
